﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddMoreMediaUserControl.ascx.cs"
    Inherits="JM.JCY.SharePointComponent.PhotoAlbum.AddMoreMedia.AddMoreMediaUserControl" %>
<link href="/_layouts/JM.JCY.Resource/scripts/plUpload/jquery-ui-1.8.9.css" rel="stylesheet"
    type="text/css" />
<link href="/_layouts/JM.JCY.Resource/scripts/plUpload/jquery.ui.plupload.css" rel="stylesheet"
    type="text/css" />
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/jquery-ui.1.8.9.min.js" type="text/javascript"></script>
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/plupload.js" type="text/javascript"></script>
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/plupload.silverlight.js"
    type="text/javascript"></script>
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/plupload.flash.js" type="text/javascript"></script>
<script src="/_layouts/JM.JCY.Resource/scripts/plUpload/jquery.ui.plupload.js" type="text/javascript"></script>
<script type="text/javascript">

    var uploader;
    $(document).ready(function () {

        $("#uploader").plupload({
            // General settings
            runtimes: 'silverlight',
            url: '/_layouts/SharePointComponent/upload.aspx',
            max_file_size: '8mb',
            max_file_count: 20,
            chunk_size: '1mb',
            unique_names: true,
            multiple_queues: true,
            multipart_params: { "currentGuid": "testValue" },

            // Rename files by clicking on their titles
            rename: true,
            // Sort files
            sortable: true,

            // Specify what files to browse for
            filters: [
			{ title: "Imagefiles", extensions: "jpg,jpeg,gif,tif,bmp,png" }
		],
            // Silverlight settings
            silverlight_xap_url: '/_layouts/JM.JCY.Resource/scripts/plUpload/plupload.silverlight.xap'
        });

        uploader = $('#uploader').plupload('getUploader');
        uploader.bind('Init', function (up, res) {
            $('a.plupload_start').css('display', 'none');
            $("#uploader_container").attr("title", "");
            $('div.plupload_header_text').text("添加照片后，请点保存。");
            $('div.plupload_header_title').text("选择照片");
            $('tr.plupload_filelist_header td.plupload_file_name').text("照片名称");
            $('tr.plupload_filelist_header td.plupload_file_status').text("状态");
            $('tr.plupload_filelist_header td.plupload_file_size').text("大小");
            $("a[id='uploader_browse']").text("添加照片");
            $("a[id='uploader_start']").text("");
            $("a[id='uploader_stop']").text("");
            $("div.plupload_progress plupload_right").text("");

        });
        uploader.bind('FilesAdded', function () {
            $("#controltoupload").text('');
        });
        LoadContorls();

    });

    function startUpload() {

        // Files in queue upload them first
        if (uploader.files.length > 0) {
            for (var i = 0; i < uploader.files.length; i++) {
                if (uploader.files[i].status == 5) {
                    uploader.files[i].status = 1;
                }
            }
            // When all files are uploaded submit form
            uploader.bind('UploadProgress', function () {
                if (uploader.total.uploaded == uploader.files.length) {
                    // to do something after all file uploaded.
                    var timeId = setTimeout(function () { step1functions(); }, 1000);
                }
            });
            var currentGuid = jQuery.Guid.New();
            $("#<%=HiddenFieldGuid.ClientID %>").val(currentGuid);
            uploader.settings.multipart_params.currentGuid = currentGuid;

            $("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body");
            $("<div class=\"datagrid-mask-msg\"></div>").html("程序正在进行中，请稍等...").appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });

            uploader.start();
        } else {
            //no file selected to do something.
            $("#controltoupload").text("您至少要选择一个照片.");
            return false;
        }
    }

    function LoadContorls() {

        var save = $("#<%=ImageButtonSave.ClientID %>");
        var cancel = $("#<%=ImageButtonCancel.ClientID %>");

        var albumId = getParameterByName("AlbumId");
        // bind cancel button
        cancel.live('click', function () {
            location.href = "ViewAlbum.aspx?AlbumId=" + albumId;
            return false;
        });

        save.live('click', function () {
            startUpload();
            return false;
        });
    }
    function step1functions() {
       __doPostBack("addmore");
        return false;
    }

    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }

</script>

<div>
    <table class="main" width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td valign="top" width="100%">
                <table class="content" width="99%">
                    <tr>
                        <td>
                            <div class="gallery">
                                <table width="100%" class="galleryTitle">
                                    <tr>
                                        <td width="60%">
                                            <h2 class="gallery">
                                                <img src="/_layouts/JM.JCY.Resource/images/相册小.png" width="24">
                                                我的相册 - 添加照片</h2>
                                        </td>
                                        <td align="right" width="40%">
                                            &nbsp;
                                        </td>
                                    </tr>
                                </table>
                                <br />
                                <table class="galleryHeader" width="100%">
                                    <tr>
                                        <td width="70%">
                                            向当前相册,添加更多的照片
                                        </td>
                                        <td width="30%" align="right">
                                            &nbsp;
                                        </td>
                                    </tr>
                                </table>
                                <table width="100%" class="galleryForm">
                                    <tr>
                                        <td>
                                            <span class="gallery">请选择你的照片</span> <span class="mandatory">*</span>
                                        </td>
                                        <td>
                                            :
                                        </td>
                                        <td>
                                            <div id="uploader">
                                                <p>
                                                    你的浏览器不支持Silverlight.</p>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                    <td></td>
                                    <td></td>
                                        <td>
                                            <span class="gallery">每张照片大小控制在8兆(MB)以内</span>
                                        </td>
                                    </tr>
                                 
                                    <tr>
                                         <td></td>
                                    <td></td>
                                        <td>
                                            <span class="ms-formvalidation" id="controltoupload" style="display: inline; color: red;">
                                            </span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right" colspan="3">
                                            <asp:ImageButton ID="ImageButtonSave" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/save.png"/>
                                            <asp:ImageButton ID="ImageButtonCancel" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/cancel.png" />
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>
                <br />
            </td>
        </tr>
    </table>
</div>

<div class="datagrid-mask">
</div>
<div class="datagrid-mask-msg">
</div>
<asp:HiddenField ID="HiddenFieldGuid" runat="server" />
